package com.corpdata.app.project.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.corpdata.core.base.AbstractBaseService;
import com.alibaba.fastjson.JSON;
import com.corpdata.app.project.dao.ProjectPartitionMapper;
import com.corpdata.app.project.entity.ProjectInfo;
import com.corpdata.app.project.entity.ProjectPartition;
import com.corpdata.app.project.service.ProjectPartitionService;
import com.corpdata.app.project.service.ProjectStationService;
import com.corpdata.common.result.Result;
import com.corpdata.common.result.util.ResultUtil;
import com.corpdata.common.utils.CorpdataUtil;

/**
 * 楼层分区
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-08 15:23:00
 */
@Service
@Transactional
public class ProjectPartitionServiceImpl extends AbstractBaseService<ProjectPartition> implements ProjectPartitionService {
	
	@Autowired
	ProjectPartitionMapper projectPartitionMapper;
	
	@Autowired
	ProjectStationService stationService;
	
	public String selPartition(String id){
		return JSON.toJSONStringWithDateFormat(projectPartitionMapper.selectById(id),"yyyy-MM-dd");
	}
	
	public Result insert(ProjectPartition record,String names){
		String id=CorpdataUtil.getUUID();
		record.setId(id);
		if(names!=null&&!"".equals(names)){
			stationService.insert(id, names);
		}
		return super.save(record);
	}
	public Result deleteById(String id) {
    	if(mapper.deleteById(id)>0){
    		stationService.deleteByPartitionId(id);
    		return ResultUtil.success();
    	}else{
    		return ResultUtil.fail();
    	}
	}

	
}
